import 'dart:convert';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_video_info/flutter_video_info.dart';

void main() {
  TestWidgetsFlutterBinding.ensureInitialized();

  // Mock MethodChannel to simulate native method calls
  const MethodChannel channel = MethodChannel('flutter_video_info');

  // Setup mock responses
  setUp(() {
    channel.setMockMethodCallHandler((MethodCall methodCall) async {
      if (methodCall.method == 'getVidInfo') {
        final String path = methodCall.arguments['path'];

        // Simulate different scenarios based on the path
        if (path.contains('valid_video')) {
          return json.encode({
            'path': path,
            'isfileexist': true,
            'title': 'test_video',
            'mimetype': 'video/mp4',
            'date': '2023-01-01',
            'location': 'test/location',
            'framerate': '30.0',
            'author': 'test_author',
            'width': '1920',
            'height': '1080',
            'orientation': '0',
            'filesize': 1024 * 1024,
            'duration': '60000.0'
          });
        } else if (path.contains('invalid_video')) {
          return json.encode({
            'path': path,
            'isfileexist': false,
          });
        } else if (path.contains('minimal_video')) {
          return json.encode({
            'path': path,
            'isfileexist': true,
            'mimetype': 'video/mp4',
            'width': '640',
            'height': '480',
            'orientation': '',
            'duration': '30000.0'
          });
        }
      }
      return null;
    });
  });

  // Cleanup after tests
  tearDown(() {
    channel.setMockMethodCallHandler(null);
  });

  group('FlutterVideoInfo', () {
    FlutterVideoInfo videoInfo = FlutterVideoInfo();

    test('getVideoInfo should return valid VideoData for valid video path',
        () async {
      // Arrange
      const String validPath = '/path/to/valid_video.mp4';

      // Act
      VideoData? result = await videoInfo.getVideoInfo(validPath);

      // Assert
      expect(result, isNotNull);
      expect(result!.path, equals(validPath));
      expect(result.title, equals('valid_video'));
      expect(result.mimetype, equals('video/mp4'));
      expect(result.date, equals('2023-01-01'));
      expect(result.location, equals('test/location'));
      expect(result.framerate, equals(30.0));
      expect(result.author, equals('test_author'));
      expect(result.width, equals(1920));
      expect(result.height, equals(1080));
      expect(result.orientation, equals(0));
      expect(result.filesize, equals(1024 * 1024));
      expect(result.duration, equals(60000.0));
    });
  });
}
